package com.aistar.controller;

import com.aistar.pojo.Customer;
import com.aistar.pojo.ResumeDeliveryRecord;
import com.aistar.service.ResumeDeliveryRecordService;
import com.aistar.service.impl.ResumeDeliveryRecordServiceImpl;
import com.aistar.util.ServerResponse;
import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;

@WebServlet(name = "ResumeDeliveryRecordServlet",urlPatterns = "/resumeDeliveryRecord")
public class ResumeDeliveryRecordServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String op = request.getParameter("op");
        switch (op){
            case "add":add(request,response);break;
        }
    }

    private void add(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Integer resumeId = Integer.valueOf(request.getParameter("resumeId"));
        Integer jobId = Integer.valueOf(request.getParameter("jobId"));
        Customer customer =(Customer) request.getSession().getAttribute("loginCustomer");
        Integer custId = customer.getCustId();

        ResumeDeliveryRecord record = new ResumeDeliveryRecord();
        record.setCustId(custId);
        record.setJobId(jobId);
        record.setResumeId(resumeId);
        record.setDeliveryTime(new Date());

        ResumeDeliveryRecordService resumeDeliveryRecordService = new ResumeDeliveryRecordServiceImpl();
       ServerResponse serverResponse =  resumeDeliveryRecordService.save(record);
        response.setContentType("text/html;charset=UTF-8");
        response.getWriter().println(JSON.toJSONString(serverResponse));

    }

        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request,response);
    }
}
